package admin

import (
	"goTong/app/hlw/api/config"
	"goTong/gtong/core/trace"
	"goTong/gtong/server/restserver"
)

func NewAPIHTTPServer(cfg *config.Config) (*restserver.Server, error) {
	//初始化open-telemetry的exporter
	trace.InitAgent(trace.Options{
		cfg.Telemetry.Name,
		cfg.Telemetry.Endpoint,
		cfg.Telemetry.Sampler,
		cfg.Telemetry.Batcher,
	})
	aRestServer := restserver.NewServer(
		restserver.WithPort(cfg.Server.HttpPort),
		restserver.WithMiddlewares(cfg.Server.Middlewares),
		restserver.WithEnableProfiling(true),
		restserver.WithMetrics(true),
		restserver.WithServiceName(cfg.Server.Name),
		restserver.WithTransName(cfg.Server.TransName),
	)
	//配置好路由
	initRouter(aRestServer, cfg)
	return aRestServer, nil
}
